package com.action.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.base.app_core.model.PoiList;
import com.xinglai.yun.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yjy on 2016/11/4.
 */
public class SearchAdapter extends BaseAdapter {

    private Context context;
    private List<PoiList> mData = new ArrayList<>();
    private String searchText;

    public SearchAdapter(Context context, List<PoiList> Data, String searchText) {
        this.context = context;
        this.mData.clear();
        this.mData.addAll(Data);
        this.searchText = searchText;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public PoiList getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.search_list_item, null);
            holder = new ViewHolder();
            holder.text = convertView.findViewById(R.id.name);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.text.setText(mData.get(position).getTitle());
        return convertView;
    }

    public void setData(List<PoiList> data) {
        if (data == null || data.isEmpty()) {
            this.mData.clear();
            this.notifyDataSetChanged();
            return;
        }
        this.mData.clear();
        this.mData.addAll(data);
        this.notifyDataSetChanged();
    }

    private class ViewHolder {
        private TextView text;
    }

}
